package fm.dongman.animefm.view.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;

import java.util.List;

import fm.dongman.animefm.R;
import fm.dongman.animefm.contractlib.IModel;
import fm.dongman.animefm.view.activity.WebViewActivity;
import fm.dongman.animefm.view.transform.GlideRoundTransform;
import fm.dongman.modellib.model.ArticleModel;

/**
 * 漫圈》最新文章
 * Created by Administrator on 2017/10/17.
 */

public class FArticlesLatestAdapter extends RecyclerView.Adapter<FArticlesLatestAdapter.ViewHolder>{
    private Context mContext;
    private List<IModel.IArticleModel> mListArticle;
    public FArticlesLatestAdapter(List<IModel.IArticleModel>ListArrticle, Context context)
    {
        mListArticle=ListArrticle;
        mContext=context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_find_new_article,null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final ArticleModel article;
        article= (ArticleModel) mListArticle.get(position);
        Glide.with(mContext)
                .load(article.getImgUrl())
                .transform(new CenterCrop(mContext),new GlideRoundTransform(mContext,4)).into( holder.ImgUrl);
        holder.Title.setText(article.getTitle());
        holder.Summary.setText(article.getSummary());
        holder.BrowseCount.setText(article.getBrowseCount()+"阅读");
        holder.CreateTime.setText(article.getCreateTime());

        //单击事件
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mContext.startActivity(WebViewActivity.getIntent(mContext,article.getArticleURL(),true));
            }
        });

    }

    @Override
    public int getItemCount() {
        return mListArticle.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView ImgUrl;
        TextView Title;
        TextView Summary;
        TextView BrowseCount;
        TextView CreateTime;
        View view;
        public ViewHolder(View itemView) {
            super(itemView);
            ImgUrl= (ImageView) itemView.findViewById(R.id.mIvArticlesHotImg);
            Title  = (TextView) itemView.findViewById(R.id.mTvFindArticleHotTitle);
            Summary= (TextView) itemView.findViewById(R.id.mTvFindArticleHotSummary);
            BrowseCount= (TextView) itemView.findViewById(R.id.mTvFindArticleHotReadNum);
            CreateTime= (TextView) itemView.findViewById(R.id.mTvFindArticleHotCreateTime);
            view=itemView.findViewById(R.id.mRlFindArticlesHotLayout);
        }
    }

}
